{
    String.prototype.replaceAll  = function(s1,s2){   
        return this.replace(new RegExp(s1,"gm"),s2);   
    }

    const util = {
        getTop : function (e) { 
            var offset = e.offsetTop; 
            if( e.offsetParent!=null) offset += this.getTop(e.offsetParent); 
            return offset; 
        },

        getLeft : function (e) { 
            var offset=e.offsetLeft; 
            if(e.offsetParent!=null) offset += this.getLeft(e.offsetParent); 
            return offset; 
        },

        loadJS : function (url) {
            var oHead = document.getElementsByTagName('HEAD').item(0); 
            var oScript= document.createElement("script"); 
            oScript.type = "text/javascript"; 
            oScript.src = url + ".js"; 
            oHead.appendChild(oScript); 
        },

        randomId : function () {
            return window.MD5((new Date()).toString()).substring(0,10);
        },

        removeEle : function (obj) {
            if( typeof obj.length === "number")  {
                obj.forEach((item)=>{
                    item.parentNode.removeChild(item);
                });
            } else {
                obj.parentNode.removeChild(obj);
            }
            this.then = this.removeEle;
            return this;
        },

        replaceEle : function (obj, newHtml) {
            let parentNode = obj.parentNode;
            let objStyle = obj.getAttribute("style");
            console.log(objStyle);
            if( typeof obj.length === "number")  {
                obj.forEach((item)=>{
                    item.parentNode.innerHTML = newHtml;
                });
            } else {
                obj.parentNode.innerHTML = newHtml;
                parentNode.setAttribute("style",objStyle);
            }
        }
    }

    if ( !window.util ) {
        window.util = util
    }
}